package cn.doourbest.learnspring.config;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.stereotype.Component;

import javax.validation.ConstraintViolation;
import javax.validation.Validation;
import javax.validation.Validator;
import java.util.Set;

@Component
@Aspect
public class AopConfig {

    @Pointcut("execution(void cn.doourbest.learnspring.service.impl.LearnSpringServiceImpl.getAge(..))")
    public void myAop(){}



    @Around(value = "myAop()")
    public Object proceed(ProceedingJoinPoint proceedingJoinPoint) throws Throwable {

        Validator validator = Validation.byProvider(HibernateValidator.class)
                .configure()
                .failFast(false)
                .buildValidatorFactory()
                .getValidator();

        Set<ConstraintViolation<Object>> validate = validator.validate(proceedingJoinPoint.getArgs()[0]);
        System.out.println("888");
        return proceedingJoinPoint.proceed();
    }
}
